package com.university.client;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.imageio.ImageIO;

import com.university.rmi.RemoteObject;
import com.university.rmi.RemoteObjectConsts;

public class ClientRMI {
public static void main (String[] arg0) {
    try {
	Registry registry = LocateRegistry.getRegistry(RemoteObjectConsts.RMI_PORT);
	RemoteObject remoteObject = (RemoteObject) registry.lookup("stub");
	
	ByteArrayOutputStream bytes = new ByteArrayOutputStream();
	
	BufferedImage src = ImageIO.read(new FileInputStream("img4.png"));
	ImageIO.write(src, "jpg", bytes);
	bytes.flush();
	byte[] inBytes = remoteObject.filter(bytes.toByteArray());
	BufferedImage dst = ImageIO.read(new ByteArrayInputStream(inBytes));
	ImageIO.write(dst, "JPG", new FileOutputStream("output.png"));
	
    } catch (RemoteException e) {
	e.printStackTrace();
    } catch (NotBoundException e) {
	e.printStackTrace();
    } catch (FileNotFoundException e) {
	e.printStackTrace();
    } catch (IOException e) {
	e.printStackTrace();
    }
    
}
}
